-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: add closeSSEStream callback to RequestHandlerExtra #1166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
commit: |
pcarleton
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm 1 nit on example
| // Track transports by session ID for session reuse | ||
| const transports = new Map<string, StreamableHTTPServerTransport>(); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // Track transports by session ID for session reuse | |
| const transports = new Map<string, StreamableHTTPServerTransport>(); |
don't think you need this any more
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought so too at first, but we do still need this at line 120 below:
// Reuse existing transport or create new one
let transport = sessionId ? transports.get(sessionId) : undefined;
Address findleyr's feedback to decouple tool code from transport: - Add CloseSSEStreamOptions type for per-invocation retry intervals - Add closeSSEStream callback to MessageExtraInfo and RequestHandlerExtra - Callback only provided when eventStore is configured - Support custom retry interval via options.retryInterval - Update ssePollingExample to use the new callback API Tools can now close SSE streams directly via extra.closeSSEStream() without needing to track or access transports explicitly.
da2e98c to
3a58ea1
Compare
| const stream = this._streamMapping.get(streamId); | ||
| if (stream) { | ||
| // If a custom retry interval is provided, send it before closing | ||
| if (retryInterval !== undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this cause problems for the client?
If the "event" field is missing, the SSE spec says that it should be treated as a "message" event.
Summary
Adds
extra.closeSSEStreamcallback toRequestHandlerExtra, addressing findleyr's feedback on #1129.This decouples tool code from the transport - tools can now close SSE streams without needing to track or access transports explicitly.
Changes
CloseSSEStreamOptionstype with optionalretryIntervalfieldMessageExtraInfowith optionalcloseSSEStreamcallbackcloseSSEStreamtoRequestHandlerExtraeventStoreis configuredNew API
Dependencies
This PR depends on #1129 (SEP-1699 SSE polling) being merged first.
Test plan